<?php

namespace App\Notifications\OrderNotifications;

use App\Models\Master;
use App\Models\Order;
use App\Notifications\OrderNotification;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;

class OrderSuccessNotification extends Notification implements OrderNotification
{
    use Queueable;

    private $order;

    /**
     * Create a new notification instance.
     *
     * @return void
     */
    public function __construct(Order $order)
    {
        $this->order = $order;
    }

    /**
     * Get the notification's delivery channels.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        return ['database'];
    }

    /**
     * Get the array representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function toArray(Master $master)
    {
        $message = <<<EOT
%s师傅，您好！您服务的订单%s，下单用户已经完成验收确认并放款。
EOT;
        $message = sprintf($message,
            $master->real_name,
            $this->order->order_number);
        return [
            'title'=>'订单交易成功提醒',
            'order_id'=>$this->order->id,
            'message'=>$message
        ];
    }
}
